/* Sokoban
 * HIT3243
 * Authors: Mike Blackney, Ben Ingarfield, Kurniawan
 */

#include "title.h"
#include "registrar.h"
#include "xfileentity.h"

#define IDC_START 1
//#define IDC_OPTIONS 2
#define IDC_HISCORE 3
#define IDC_INSTRUCT 4
#define IDC_QUIT 5
#define IDC_RADIOCC 6
#define IDC_RADIOFC 7
#define IDC_RADIOAC 8

Title::Title( ) {
}

Title* const Title::Instance( ) {
	static Title instance;
	return &instance;
}

HRESULT Title::Load( ) {

	HRESULT hr;
	
	V_RETURN(GameStateGUI::Load( ));

	// Add the GUI items
	const D3DSURFACE_DESC* d = DXUTGetBackBufferSurfaceDesc( );

	V_RETURN(dialog.AddRadioButton(IDC_RADIOCC, 1, L"Classic Camera", 150, 325, 200, 25, false, L'1'));
    V_RETURN(dialog.AddRadioButton(IDC_RADIOFC, 1, L"Follow Camera", 350, 325, 200, 25, true, L'2'));
    V_RETURN(dialog.AddRadioButton(IDC_RADIOAC, 1, L"Action Camera", 550, 325, 200, 25, false, L'3'));
	
	//V_RETURN(dialog.AddButton(IDC_START, Registrar::sGameType.c_str( ), d->Width / 2 - 100, d->Height / 2, 200, 50, 'N'));
	V_RETURN(dialog.AddButton(IDC_START, L"Play Game", d->Width / 2 - 100, d->Height / 2 + 100, 200, 50, 'N'));
	
	V_RETURN(dialog.AddButton(IDC_HISCORE, L"High Scores", d->Width / 2 - 350, d->Height / 2 + 100, 200, 50, 'S'));
	//V_RETURN(dialog.AddButton(IDC_OPTIONS, L"Options", d->Width / 2 - 100, d->Height / 2 + 100, 200, 50, 'O'));
	V_RETURN(dialog.AddButton(IDC_INSTRUCT, L"Help", d->Width / 2 + 150, d->Height / 2 + 100, 200, 50, 'H'));
	V_RETURN(dialog.AddButton(IDC_QUIT, L"Quit", d->Width / 2 - 100, d->Height / 2 + 200, 200, 50, 'Q'));

	// Get the title sprite:
	V_RETURN(title.CreateFromFile(L"SokobanTitle.png"));
	//V_RETURN(title.CreateFromFile(L"s_title.jpg"));
	//title.SetPosition( d->Width / 2 - title.GetWidth( ) / 2, d->Height / 4 - title.GetHeight( ) / 2 );

	// Enable mouse
	DXUTSetCursorSettings(true, false);
	DXUTGetD3DDevice( )->ShowCursor(true);

	dxf::DXFSetClear(true);
	dxf::DXFSetClearColor(BLACK);
	return S_OK;
}

void Title::Unload( ) {
	GameStateGUI::Unload( );
	title.Unload( );
	Registrar::bEnteringScore = false;
}

void Title::Update(double fTime, float fElapsedTime) {
}

void Title::Render2D(double fTime, float fElapsedTime) {
	// Draw the title:
	title.Render2D( );
}

void Title::Resize(const D3DSURFACE_DESC* d) {
	// Put the dialog back in the corner (this step probably unnecessary)
	dialog.SetLocation( 0, 0 );

	// Make its size match the size of the screen
	dialog.SetSize( d->Width, d->Height );
}

bool Title::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	// Pass windows messages to the resource manager and all the gui objects
	if (GameStateGUI::MsgProc(hWnd, uMsg, wParam, lParam)) return true;
	return false;	// let the engine handle everything else.
}

void Title::OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext ) {
    switch( nControlID ) {
	case IDC_RADIOCC:	// the 'Classic Camera' radio button was selected
		Registrar::iDifficulty = 0;
		break;

	case IDC_RADIOFC:	// the 'Follow Camera' radio button was selected
		Registrar::iDifficulty = 1;
		break;

	case IDC_RADIOAC:	// the 'Action Camera' radio button was selected
		Registrar::iDifficulty = 2;
		break;

	case IDC_START:
		dxf::DXFChangeState(Registrar::kGame);
		break;
	/*
	case IDC_OPTIONS:
		dxf::DXFChangeState(Registrar::kOptions);
		break;
		*/
	case IDC_HISCORE:
		dxf::DXFChangeState(Registrar::kHiScore);
		break;
	case IDC_INSTRUCT:
		dxf::DXFChangeState(Registrar::kHelp);
		break;
	case IDC_QUIT:
		PostQuitMessage(0);
		break;
	default:
		assert(false);
		break;
	}
}


